package org.baojie.server.refactor;

/**
 * @author baojie
 * @description: TODO
 * @date 2021/10/27上午11:09
 */
public class SourceDetail {

    private String domain;                      // 用户的域名账号名称,可以理解为是用户的别名或者是对应公司内部的员工id
    private String guid = "";                   // 调用数据源列表接口返回的 数据源 guid
    private String adid = "";                   // 调用数据源列表接口返回的 数据源 adid
    private String gid = "";                    // 调用数据源列表接口返回的 数据源 gid
    private String user;                        // 用户名
    private String pwd;                         // 密码
    private String jdbc;                        // 连接串
    private String dbName;                      // 数据库名称
    private String ip;                          // ip
    private String port;                        // 端口
    private DataBaseType dataBaseType = DataBaseType.MySql; // 数据源类型
    private boolean proxy = false;              // 是否是一个代理的数据源,主要针对mysql或者oracle数据库
    private String proxyKey = "";

    public SourceDetail() {

    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        if (null != guid) {
            String temp = guid.trim();
            this.guid = temp;
        }
    }

    public String getGid() {
        return gid;
    }

    public void setGid(String gid) {
        if (null != gid) {
            String temp = gid.trim();
            this.gid = temp;
        }
    }

    // 使用 adid 与 domain 一起作为key
    public String getAdid() {
        return adid;
    }

    // 使用 adid 与 domain 一起作为key
    public void setAdid(String adid) {
        if (null != adid) {
            String temp = adid.trim();
            this.adid = temp;
        }
    }

    // 使用 adid 与 domain 一起作为key
    public String getDomain() {
        return domain;
    }

    // 使用 adid 与 domain 一起作为key
    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public String getJdbc() {
        return jdbc;
    }

    public void setJdbc(String jdbc) {
        this.jdbc = jdbc;
    }

    public String getDbName() {
        return dbName;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public DataBaseType getDataBaseType() {
        return dataBaseType;
    }

    public void setDataBaseType(DataBaseType dataBaseType) {
        this.dataBaseType = dataBaseType;
    }

    public boolean isProxy() {
        return proxy;
    }

    public void setProxy(boolean proxy) {
        this.proxy = proxy;
    }

    public final String proxyKey() {
        String dbn = getDbName();
        String ip = getIp();
        String port = getPort();
        StringBuilder builder = new StringBuilder();
        builder.append(ip);
        builder.append(":");
        builder.append(port);
        builder.append(":");
        builder.append(dbn);
        return builder.toString();
    }

    // 作为数据库数据源的唯一标记
    public final String oceanSandID() {
        String domain = getDomain();
        String user = getUser();
        String dbType = getDataBaseType().getTypeFullName();
        String adid = getAdid();
        String ip = getIp();
        String port = getPort();
        String dbn = getDbName();
        StringBuilder builder = new StringBuilder();
        builder.append(domain);
        builder.append("-");
        builder.append(adid);
        builder.append("-");
        builder.append(dbType);
        builder.append("-");
        builder.append(user);
        builder.append("-");
        builder.append(ip);
        builder.append("-");
        builder.append(port);
        builder.append("-");
        builder.append(dbn);
        return builder.toString();
    }

    @Override
    public String toString() {
        return "SourceDetail{" +
                "domain='" + domain + '\'' +
                ", guid='" + guid + '\'' +
                ", adid='" + adid + '\'' +
                ", gid='" + gid + '\'' +
                ", user='" + user + '\'' +
                ", jdbc='" + jdbc + '\'' +
                ", dbName='" + dbName + '\'' +
                ", ip='" + ip + '\'' +
                ", port='" + port + '\'' +
                ", dbType=" + dataBaseType +
                '}';
    }

}
